package com.zy.qudadid.ui.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.zy.lcpassenger.R;
import com.zy.qudadid.model.MyCoupon;
import com.zy.qudadid.presenter.MyCouponPresenter;
import com.zy.qudadid.ui.activity.base.RecycleViewActivity;
import com.zy.qudadid.ui.adapter.MyCouponAdapter;
import com.zy.qudadid.ui.view.MyCouponView;
import com.zy.qudadid.utils.AESCrypt;
import com.zy.qudadid.utils.StringUtil;
import com.zy.qudadid.utils.UserUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class MyCouponActivity extends RecycleViewActivity<MyCouponPresenter,MyCouponAdapter,MyCoupon> implements MyCouponView {

    @Override
    protected MyCouponAdapter provideAdapter() {
        return new MyCouponAdapter(getContext());
    }

    @Override
    protected RecyclerView.LayoutManager provideLayoutManager() {
        return new LinearLayoutManager(getContext());
    }

    @Override
    protected CharSequence provideTitle() {
        return "我的优惠券";
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_my_coupon;
    }

    @Override
    public void initListeners() {

    }

    @Override
    protected void initThings(Bundle savedInstanceState) {
        super.initThings(savedInstanceState);


        Map<String,String> map = new HashMap<>();
        map.put("user_id",new UserUtil(getContext()).getUserId());
        String json = StringUtil.toJson(map);
        try {
            String data1 = AESCrypt.getInstance().encrypt(json);
            String d = StringUtil.replaceBlank(data1);
            presenter.getMyCouponList(d);
        } catch (Exception ex) {
        }
    }

    @Override
    public MyCouponPresenter createPresenter() {
        return new MyCouponPresenter();
    }

    @Override
    public void onItemClick(View view, int pos, MyCoupon item) {

    }

    @Override
    public void success(ArrayList<MyCoupon> data) {
        bd(data);
    }

    @Override
    public void error(String str) {
        toast(str);
    }
}
